import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '网址',
    align: "center",
    sorter: true,
    dataIndex: 'url'
  },
  {
    title: '图标',
    align: "center",
    dataIndex: 'ico',
    width: 80,
    slots: { customRender: 'imgSlot' },
  },
  {
    title: '名称',
    align: "center",
    sorter: true,
    dataIndex: 'name'
  },
  {
    title: '类型',
    align: "center",
    sorter: true,
    dataIndex: 'type_dictText'
  },
  {
    title: '状态',
    align: "center",
    sorter: true,
    dataIndex: 'state_dictText'
  },
  {
    title: '是否推荐',
    align: "center",
    sorter: true,
    dataIndex: 'isRecommend_dictText'
  },
  {
    title: '创建时间',
    align: "center",
    sorter: true,
    dataIndex: 'createTime'
  },
];

//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "网址",
    field: 'url',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "名称",
    field: 'name',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "类型",
    field: 'type',
    component: 'JSearchSelect',
    componentProps: {
      dict: "fav_category,name,id"
    },
    colProps: { span: 6 },
  },
  {
    label: "状态",
    field: 'state',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "dict_item_status"
    },
    colProps: { span: 6 },
  },
  {
    label: "是否推荐",
    field: 'isRecommend',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "is_recommend"
    },
    colProps: { span: 6 },
  },
];

//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '网址',
    field: 'url',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入网址!' },
        { pattern: /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:\/~+#]*[\w\-@?^=%&\/~+#])?$/, message: '请输入正确的网址!' },
      ];
    },
  },
  {
    label: '图标',
    field: 'ico',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入图标!' },
      ];
    },
  },

  {
    label: '名称',
    field: 'name',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入名称!' },
      ];
    },
  },
  {
    label: '类型',
    field: 'type',
    component: 'JSearchSelect',
    componentProps: {
      dict: "fav_category,name,id"
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入类型!' },
      ];
    },
  },
  {
    label: '状态',
    field: 'state',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "dict_item_status"
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入状态!' },
      ];
    },
  },
  {
    label: '是否推荐',
    field: 'isRecommend',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "is_recommend"
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入是否推荐!' },
      ];
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];
